--
-- Author: ping.wang
-- Date: 2019-06-28 11:32:15
--
-- RewardHeroTrearsureTipsPanel
--

local ClassRef = app.mvc.createPanelClass(...)
local IconRender = require("app.widget.renders.IconRender")

--data =
function ClassRef.createWithData(data, node)
    local sprite = ClassRef.extend(node or cc.CSLoader:createNode(Res.RewardHeroTrearsureTipsPanel))
    if node == nil then
        ccui.Helper:doLayout(sprite)
    end
    sprite:init(data)
    return sprite
end
function ClassRef.create(node)
    return ClassRef.createWithData(nil, node)
end

--
function ClassRef:init(data)
    self.super.init(self, data)

    self._icon1 = IconRender.create(self._ui.Panel_1:findChild("icon"))
    self._icon1:setTipEnable(true)
    self._icon2 = IconRender.create(self._ui.Panel_2:findChild("icon"))
    self._icon2:setTipEnable(true)

    self:setContentSize( self._ui.Panel:getContentSize() )
    self:refresh()
end

function ClassRef:refresh()
    if self._data then
        self:setVisible( true )

        local data = self._data
        self:_initPanel(self._ui.Panel_1, data[1], self._icon1, false)
        self:_initPanel(self._ui.Panel_2, data[2], self._icon2, true)
    else
        self:setVisible( false )
    end
end

function ClassRef:_initPanel(panel, reward, icon, isGolden)
    icon:setData(reward)
    panel:findChild("name"):setString(reward:getName())
    if isGolden then
        panel:findChild("text"):setString(L("battlepass_string11"))
    else
        panel:findChild("text"):setString(L("battlepass_string10"))
    end
end

function ClassRef:onOperate(cb)
    self._onOperate = cb
end

return ClassRef
